<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>客户中心 - 工单管理系统</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <style>
        :root {
            --customer-primary: #17a2b8;
            --customer-secondary: #6c757d;
            --sidebar-width: 250px;
        }

        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background-color: #f8f9fa;
        }

        .sidebar {
            position: fixed;
            top: 0;
            left: 0;
            height: 100vh;
            width: var(--sidebar-width);
            background: linear-gradient(180deg, var(--customer-primary) 0%, #138496 100%);
            color: white;
            z-index: 1000;
            transition: all 0.3s ease;
        }

        .sidebar.collapsed {
            width: 70px;
        }

        .sidebar-header {
            padding: 20px;
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
            text-align: center;
        }

        .sidebar-header h4 {
            margin: 0;
            font-weight: 600;
        }

        .sidebar-header .collapse-btn {
            position: absolute;
            top: 20px;
            right: 15px;
            background: none;
            border: none;
            color: white;
            font-size: 18px;
            cursor: pointer;
        }

        .sidebar-menu {
            padding: 20px 0;
        }

        .menu-item {
            display: flex;
            align-items: center;
            padding: 12px 20px;
            color: rgba(255, 255, 255, 0.8);
            text-decoration: none;
            transition: all 0.3s ease;
            border-left: 3px solid transparent;
        }

        .menu-item:hover {
            background: rgba(255, 255, 255, 0.1);
            color: white;
            border-left-color: white;
        }

        .menu-item.active {
            background: rgba(255, 255, 255, 0.15);
            color: white;
            border-left-color: white;
        }

        .menu-item i {
            width: 20px;
            margin-right: 12px;
            text-align: center;
        }

        .menu-text {
            transition: opacity 0.3s ease;
        }

        .sidebar.collapsed .menu-text {
            opacity: 0;
            width: 0;
        }

        .main-content {
            margin-left: var(--sidebar-width);
            min-height: 100vh;
            transition: all 0.3s ease;
        }

        .sidebar.collapsed + .main-content {
            margin-left: 70px;
        }

        .top-navbar {
            background: white;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
            padding: 15px 30px;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .user-info {
            display: flex;
            align-items: center;
            gap: 15px;
        }

        .user-avatar {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background: var(--customer-primary);
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-weight: 600;
        }

        .content-area {
            padding: 30px;
        }

        .welcome-card {
            background: linear-gradient(135deg, var(--customer-primary) 0%, #138496 100%);
            color: white;
            border-radius: 20px;
            padding: 30px;
            margin-bottom: 30px;
            box-shadow: 0 10px 30px rgba(23, 162, 184, 0.3);
        }

        .welcome-card h2 {
            margin: 0 0 10px 0;
            font-weight: 600;
        }

        .welcome-card p {
            margin: 0;
            opacity: 0.9;
        }

        .quick-actions {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 20px;
            margin-bottom: 30px;
        }

        .action-card {
            background: white;
            border-radius: 15px;
            padding: 25px;
            text-align: center;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            transition: all 0.3s ease;
            cursor: pointer;
            border: 2px solid transparent;
        }

        .action-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
            border-color: var(--customer-primary);
        }

        .action-card i {
            font-size: 2.5rem;
            color: var(--customer-primary);
            margin-bottom: 15px;
        }

        .action-card h5 {
            margin: 0 0 10px 0;
            font-weight: 600;
            color: #333;
        }

        .action-card p {
            margin: 0;
            color: #6c757d;
            font-size: 0.9em;
        }

        .ticket-list {
            background: white;
            border-radius: 15px;
            padding: 25px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            margin-bottom: 30px;
        }

        .ticket-item {
            display: flex;
            align-items: center;
            padding: 20px;
            border: 1px solid #e9ecef;
            border-radius: 10px;
            margin-bottom: 15px;
            transition: all 0.3s ease;
        }

        .ticket-item:hover {
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
            transform: translateY(-2px);
        }

        .ticket-icon {
            width: 50px;
            height: 50px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-right: 20px;
            font-size: 20px;
        }

        .ticket-icon.open {
            background: #e3f2fd;
            color: #1976d2;
        }

        .ticket-icon.in-progress {
            background: #fff3e0;
            color: #f57c00;
        }

        .ticket-icon.resolved {
            background: #e8f5e8;
            color: #388e3c;
        }

        .ticket-icon.closed {
            background: #f3e5f5;
            color: #7b1fa2;
        }

        .ticket-info {
            flex: 1;
        }

        .ticket-title {
            font-weight: 600;
            margin-bottom: 5px;
            color: #333;
            font-size: 1.1em;
        }

        .ticket-meta {
            color: #6c757d;
            font-size: 0.9em;
        }

        .ticket-status {
            padding: 6px 16px;
            border-radius: 20px;
            font-size: 0.8em;
            font-weight: 600;
            text-transform: uppercase;
        }

        .ticket-status.open {
            background: #e3f2fd;
            color: #1976d2;
        }

        .ticket-status.in-progress {
            background: #fff3e0;
            color: #f57c00;
        }

        .ticket-status.resolved {
            background: #e8f5e8;
            color: #388e3c;
        }

        .ticket-status.closed {
            background: #f3e5f5;
            color: #7b1fa2;
        }

        .btn-customer {
            background: var(--customer-primary);
            border-color: var(--customer-primary);
            color: white;
        }

        .btn-customer:hover {
            background: #138496;
            border-color: #138496;
            color: white;
        }

        .btn-outline-customer {
            border-color: var(--customer-primary);
            color: var(--customer-primary);
        }

        .btn-outline-customer:hover {
            background: var(--customer-primary);
            border-color: var(--customer-primary);
            color: white;
        }

        .stats-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
            gap: 20px;
            margin-bottom: 30px;
        }

        .stat-card {
            background: white;
            border-radius: 15px;
            padding: 20px;
            text-align: center;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            border-top: 4px solid var(--customer-primary);
        }

        .stat-card h3 {
            font-size: 2rem;
            font-weight: 700;
            margin: 0;
            color: var(--customer-primary);
        }

        .stat-card p {
            margin: 5px 0 0 0;
            color: #6c757d;
            font-weight: 500;
        }

        .empty-state {
            text-align: center;
            padding: 60px 20px;
            color: #6c757d;
        }

        .empty-state i {
            font-size: 4rem;
            margin-bottom: 20px;
            color: #dee2e6;
        }

        @media (max-width: 768px) {
            .sidebar {
                transform: translateX(-100%);
            }

            .sidebar.show {
                transform: translateX(0);
            }

            .main-content {
                margin-left: 0;
            }

            .quick-actions {
                grid-template-columns: 1fr;
            }

            .stats-grid {
                grid-template-columns: repeat(2, 1fr);
            }
        }
    </style>
</head>
<body>
    <!-- 侧边栏 -->
    <div class="sidebar" id="sidebar">
        <div class="sidebar-header">
            <h4><i class="fas fa-user me-2"></i><span class="menu-text">客户中心</span></h4>
            <button class="collapse-btn" onclick="toggleSidebar()">
                <i class="fas fa-bars"></i>
            </button>
        </div>
        <nav class="sidebar-menu">
            <a href="#" class="menu-item active" data-section="dashboard">
                <i class="fas fa-home"></i>
                <span class="menu-text">首页</span>
            </a>
            <a href="#" class="menu-item" data-section="my-tickets">
                <i class="fas fa-ticket-alt"></i>
                <span class="menu-text">我的工单</span>
            </a>
            <a href="#" class="menu-item" data-section="new-ticket">
                <i class="fas fa-plus-circle"></i>
                <span class="menu-text">新建工单</span>
            </a>
            <a href="#" class="menu-item" data-section="feedback">
                <i class="fas fa-comments"></i>
                <span class="menu-text">意见反馈</span>
            </a>
            <a href="#" class="menu-item" data-section="profile">
                <i class="fas fa-user-circle"></i>
                <span class="menu-text">个人中心</span>
            </a>
            <a href="#" class="menu-item" data-section="help">
                <i class="fas fa-question-circle"></i>
                <span class="menu-text">帮助中心</span>
            </a>
        </nav>
    </div>

    <!-- 主内容区 -->
    <div class="main-content">
        <!-- 顶部导航栏 -->
        <div class="top-navbar">
            <div>
                <button class="btn btn-outline-secondary d-md-none" onclick="toggleSidebar()">
                    <i class="fas fa-bars"></i>
                </button>
                <h5 class="mb-0 d-none d-md-inline">客户中心</h5>
            </div>
            <div class="user-info">
                <div class="dropdown">
                    <button class="btn btn-outline-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown">
                        <div class="user-avatar" id="userAvatar">C</div>
                        <span class="ms-2" id="userName">客户</span>
                    </button>
                    <ul class="dropdown-menu dropdown-menu-end">
                        <li><a class="dropdown-item" href="#" onclick="showProfile()">
                            <i class="fas fa-user me-2"></i>个人资料
                        </a></li>
                        <li><a class="dropdown-item" href="#" onclick="showSettings()">
                            <i class="fas fa-cog me-2"></i>设置
                        </a></li>
                        <li><hr class="dropdown-divider"></li>
                        <li><a class="dropdown-item" href="#" onclick="logout()">
                            <i class="fas fa-sign-out-alt me-2"></i>退出登录
                        </a></li>
                    </ul>
                </div>
            </div>
        </div>

        <!-- 内容区域 -->
        <div class="content-area">
            <!-- 首页 -->
            <div id="dashboard-section">
                <!-- 欢迎卡片 -->
                <div class="welcome-card">
                    <h2 id="welcomeMessage">欢迎回来！</h2>
                    <p>您可以通过以下方式快速开始使用我们的服务</p>
                </div>

                <!-- 快速操作 -->
                <div class="quick-actions">
                    <div class="action-card" onclick="createNewTicket()">
                        <i class="fas fa-plus-circle"></i>
                        <h5>新建工单</h5>
                        <p>提交新的技术支持请求</p>
                    </div>
                    <div class="action-card" onclick="viewMyTickets()">
                        <i class="fas fa-ticket-alt"></i>
                        <h5>我的工单</h5>
                        <p>查看和管理您的工单</p>
                    </div>
                    <div class="action-card" onclick="submitFeedback()">
                        <i class="fas fa-comments"></i>
                        <h5>意见反馈</h5>
                        <p>分享您的使用体验</p>
                    </div>
                    <div class="action-card" onclick="viewHelp()">
                        <i class="fas fa-question-circle"></i>
                        <h5>帮助中心</h5>
                        <p>查找常见问题解答</p>
                    </div>
                </div>

                <!-- 统计概览 -->
                <div class="stats-grid">
                    <div class="stat-card">
                        <h3 id="totalTickets">0</h3>
                        <p>总工单数</p>
                    </div>
                    <div class="stat-card">
                        <h3 id="openTickets">0</h3>
                        <p>进行中</p>
                    </div>
                    <div class="stat-card">
                        <h3 id="resolvedTickets">0</h3>
                        <p>已解决</p>
                    </div>
                    <div class="stat-card">
                        <h3 id="satisfactionScore">0</h3>
                        <p>满意度</p>
                    </div>
                </div>

                <!-- 最近工单 -->
                <div class="ticket-list">
                    <div class="d-flex justify-content-between align-items-center mb-3">
                        <h5 class="mb-0">最近工单</h5>
                        <button class="btn btn-outline-customer" onclick="viewAllTickets()">
                            查看全部 <i class="fas fa-arrow-right ms-1"></i>
                        </button>
                    </div>
                    <div id="recentTickets">
                        <!-- 动态加载工单列表 -->
                    </div>
                </div>
            </div>

            <!-- 其他页面内容 -->
            <div id="other-sections" style="display: none;">
                <!-- 其他页面内容将在这里动态加载 -->
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        // 全局变量
        const API_BASE_URL = 'http://localhost:9090/api';
        let currentUser = null;

        // 页面加载完成后初始化
        document.addEventListener('DOMContentLoaded', async () => {
            // 检查登录状态
            if (!await checkAuth()) {
                window.location.href = 'login.html';
                return;
            }

            // 加载用户信息
            await loadUserInfo();
            
            // 加载仪表板数据
            await loadDashboardData();
            
            // 绑定事件
            bindEvents();
        });

        // 检查认证状态
        async function checkAuth() {
            const token = localStorage.getItem('token');
            if (!token) return false;

            try {
                const response = await fetch(`${API_BASE_URL}/auth/me`, {
                    headers: {
                        'Authorization': `Bearer ${token}`
                    }
                });

                if (response.ok) {
                    const data = await response.json();
                    if (data.success && data.data.role === 'CUSTOMER') {
                        currentUser = data.data;
                        return true;
                    }
                }
            } catch (error) {
                console.error('认证检查失败:', error);
            }

            return false;
        }

        // 加载用户信息
        async function loadUserInfo() {
            if (currentUser) {
                const userName = currentUser.fullName || currentUser.username;
                document.getElementById('userName').textContent = userName;
                document.getElementById('userAvatar').textContent = userName.charAt(0).toUpperCase();
                document.getElementById('welcomeMessage').textContent = `欢迎回来，${userName}！`;
            }
        }

        // 加载仪表板数据
        async function loadDashboardData() {
            try {
                // 模拟数据
                document.getElementById('totalTickets').textContent = '12';
                document.getElementById('openTickets').textContent = '3';
                document.getElementById('resolvedTickets').textContent = '8';
                document.getElementById('satisfactionScore').textContent = '4.8';

                // 加载最近工单
                loadRecentTickets();
            } catch (error) {
                console.error('加载仪表板数据失败:', error);
            }
        }

        // 加载最近工单
        function loadRecentTickets() {
            const tickets = [
                {
                    id: 1,
                    title: '系统登录问题',
                    status: 'open',
                    created: '2小时前',
                    ticketNumber: '#T001234'
                },
                {
                    id: 2,
                    title: '数据导出功能异常',
                    status: 'in-progress',
                    created: '1天前',
                    ticketNumber: '#T001235'
                },
                {
                    id: 3,
                    title: '页面显示错误',
                    status: 'resolved',
                    created: '3天前',
                    ticketNumber: '#T001236'
                }
            ];

            const container = document.getElementById('recentTickets');
            
            if (tickets.length === 0) {
                container.innerHTML = `
                    <div class="empty-state">
                        <i class="fas fa-ticket-alt"></i>
                        <h5>暂无工单</h5>
                        <p>您还没有提交过工单，点击上方按钮创建第一个工单吧！</p>
                        <button class="btn btn-customer" onclick="createNewTicket()">
                            <i class="fas fa-plus me-2"></i>新建工单
                        </button>
                    </div>
                `;
            } else {
                container.innerHTML = tickets.map(ticket => `
                    <div class="ticket-item">
                        <div class="ticket-icon ${ticket.status}">
                            <i class="fas fa-ticket-alt"></i>
                        </div>
                        <div class="ticket-info">
                            <div class="ticket-title">${ticket.ticketNumber} - ${ticket.title}</div>
                            <div class="ticket-meta">创建时间：${ticket.created}</div>
                        </div>
                        <div class="ticket-status ${ticket.status}">${getStatusText(ticket.status)}</div>
                        <div class="ms-3">
                            <button class="btn btn-sm btn-outline-customer" onclick="viewTicket(${ticket.id})">
                                <i class="fas fa-eye"></i>
                            </button>
                        </div>
                    </div>
                `).join('');
            }
        }

        // 获取状态文本
        function getStatusText(status) {
            const statusMap = {
                'open': '待处理',
                'in-progress': '处理中',
                'resolved': '已解决',
                'closed': '已关闭'
            };
            return statusMap[status] || status;
        }

        // 绑定事件
        function bindEvents() {
            // 菜单事件
            const menuItems = document.querySelectorAll('.menu-item');
            menuItems.forEach(item => {
                item.addEventListener('click', (e) => {
                    e.preventDefault();
                    
                    menuItems.forEach(mi => mi.classList.remove('active'));
                    item.classList.add('active');
                    
                    const section = item.dataset.section;
                    handleMenuClick(section);
                });
            });
        }

        // 处理菜单点击
        function handleMenuClick(section) {
            if (section === 'dashboard') {
                document.getElementById('dashboard-section').style.display = 'block';
                document.getElementById('other-sections').style.display = 'none';
            } else {
                document.getElementById('dashboard-section').style.display = 'none';
                document.getElementById('other-sections').style.display = 'block';
                loadPageContent(section);
            }
        }

        // 加载页面内容
        function loadPageContent(section) {
            const container = document.getElementById('other-sections');
            const titles = {
                'my-tickets': '我的工单',
                'new-ticket': '新建工单',
                'feedback': '意见反馈',
                'profile': '个人中心',
                'help': '帮助中心'
            };
            container.innerHTML = `<h2>${titles[section] || '未知页面'}</h2><p>此功能正在开发中...</p>`;
        }

        // 快速操作函数
        function createNewTicket() {
            alert('新建工单功能正在开发中...');
        }

        function viewMyTickets() {
            handleMenuClick('my-tickets');
        }

        function submitFeedback() {
            alert('意见反馈功能正在开发中...');
        }

        function viewHelp() {
            alert('帮助中心功能正在开发中...');
        }

        function viewAllTickets() {
            handleMenuClick('my-tickets');
        }

        function viewTicket(ticketId) {
            alert(`查看工单 #${ticketId} 的详细信息`);
        }

        // 切换侧边栏
        function toggleSidebar() {
            const sidebar = document.getElementById('sidebar');
            sidebar.classList.toggle('collapsed');
        }

        // 显示个人资料
        function showProfile() {
            alert('个人资料功能正在开发中...');
        }

        // 显示设置
        function showSettings() {
            alert('设置功能正在开发中...');
        }

        // 退出登录
        function logout() {
            if (confirm('确定要退出登录吗？')) {
                localStorage.clear();
                window.location.href = 'login.html';
            }
        }
    </script>
</body>
</html>
